package com.nothing.thread.hashmap;

/**
 * 北互金-产登-工具base64
 *
 * @author bhj-demo
 */
public class HexUtils {
    private static final String HEX = "0123456789abcdef";

    public HexUtils() {
    }

    public static String byte2Hex(byte[] bytes) {
        String result = "";
        if (bytes != null) {
            for (int i = 0; i < bytes.length; ++i) {
                result = result + "0123456789abcdef".charAt(bytes[i] >> 4 & 15);
                result = result + "0123456789abcdef".charAt(bytes[i] & 15);
            }
        }

        return result;
    }

    public static byte[] hex2Byte(String text) throws Exception {
        String hexText = text;
        if (text.length() % 2 == 1) {
            hexText = "0" + text;
        }

        hexText = hexText.toLowerCase();
        int len = hexText.length() / 2;
        byte[] result = new byte[len];

        for (int i = 0; i < len; ++i) {
            String s = hexText.substring(2 * i, 2 * i + 2);
            result[i] = (byte) (Integer.parseInt(s, 16) & 255);
        }

        return result;
    }

    public static void main(String[] args) {
        try {
            String s = "10000000";
            byte[] data = hex2Byte(s);
            String s1 = byte2Hex(data);
            System.out.println(s1);
            if (s.equals(s1)) {
                System.out.println("ok");
            }
        } catch (Exception var4) {
            var4.printStackTrace();
        }

    }
}


